package com.sgx.learning.luban.arithmetic.sort;

import java.util.Arrays;

public class BubblingSort {

    public static int[] sort(int[] arr){
        int length = arr.length;
        for (int i = 1;i < length;i++) {
            for (int j = 0;j < length - i;j++) {
                if(arr[j] > arr[j+1]) {
                    arr[j] = arr[j] + arr[j+1];
                    arr[j+1] = arr[j] - arr[j+1];
                    arr[j] = arr[j] - arr[j+1];
                }
            }
        }
        return arr;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{5,3,10,22,1};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
